<script>
	import config from "@/config";
	export default {
		onLaunch: function() {
			console.log('App Launch')
			let sys = uni.getSystemInfoSync();
			let statusH =sys.statusBarHeight;
			//let statusH =sys.statusBarHeight-10;
			//let system=sys.system;
			//let navH = statusH + (system.indexOf('iOS') > -1 ? 40 : 44);
			statusH = statusH?statusH:'';
			this.$storage.set("statusH", statusH);
			//this.$storage.set("navH", navH);
			console.log(statusH, "状态栏高度")
			//console.log(navH, "导航栏高度");
		},
		onShow: function() {
			let users = this.$storage.getJson("users");
			if(users){
				//console.log(users)
				//uni.setTabBarBadge({ index: 2, text: users.shop_count.toString() });
				uni.setTabBarBadge({ index: 2, text: 0 });
			}else{
				uni.removeTabBarBadge({ index: 2 })
			}
			// #ifdef MP
			//if(users == null){
				this.getUser();
			//}
			console.log('11111',users)
			// #endif	
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			getUser: function() {
				//调用登录接口
				uni.login({
					success: function(res) {
						var code = res.code;
						//console.log('111111111111',code)
						uni.request({
							url: config.uni_app_web_api_url + '/wxlogin',
							method: 'post',
							data: {
								code: code
							},
							header: {
								'Content-Type': 'application/x-www-form-urlencoded'
							},
							success: function(res) {
								//--init data        
								var data = res.data;
								if (data.status == 0) {
									uni.showToast({
										title: data.msg,
										duration: 2000
									});
									return false;
								}else{
									if(data.data.id){
										//this.$store.commit("UPDATEUSERS", data.data);
										uni.setStorageSync('users',JSON.stringify(data.data));
									}else{
										uni.setStorageSync('wx_openid', data.data.wx_openid);
									}
								}
								//uni.setStorageSync('sessionId', data.session_key);
							},
							fail: function(e) {
								uni.showToast({
									title: '网络异常！err:getsessionkeys',
									duration: 2000
								});
							},
						});
					}
				});
			}
		}
	}
</script>

<style>
	@import '~@/style.css';
	body { background-color: #f8f8f8; }
	.clear:after { content:" "; font-size:0; display:block; height:0; clear:both; visibility:hidden; }
</style>
